/*
 * BanBu_VIPAlert
 * @description 本文件提供视频认证弹出提示的文件
 * @package
 * @author 		***
 * @copyright
 * @version 		***
 * @description 本文件提供视频认证弹出提示的文件
 */

#import "BanBu_VIPAlert.h"
#import "BanBu_ApplyVipViewController.h"
#import "BanBu_VideoAuthenViewController.h"
#import "AppDataManager.h"
static BanBu_VIPAlert *vipAlert = nil;
@implementation BanBu_VIPAlert
{
    UIView * _adView;
    //区分要跳转界面，根据原来的alert.tag值100.101
    NSInteger _flag;
}

- (void)dealloc
{
    [_adView release];
    _adView = nil;
    [super dealloc];
}
+(BanBu_VIPAlert *)shareInstance
{
    @synchronized(self)
    {
        if(vipAlert == nil)
        {
            vipAlert = [[self alloc] init];
        }
        
    }
    return vipAlert;
}
-(void)GoVIPApplyViewAlertFor:(UIViewController *)_viewController title:(NSString *)_title message:(NSString *)_message
{
    _controller = _viewController;
    //2014年11月19日16:43:17 by 尹林
    _flag = 100;
    [self creatverifyNoticeView];
    [_controller.navigationController.view addSubview:_adView];
    
    return;
    //    //完成
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:_title message:_message delegate:self cancelButtonTitle:NSLocalizedString(@"取消", nil) otherButtonTitles:NSLocalizedString(@"applyNow", nil), nil];
    alert.tag = 100;
    [alert show];
    [alert release];
}
-(void)GoVerifyApplyViewAlertFor:(UIViewController *)_viewController title:(NSString *)_title message:(NSString *)_message
{
    _controller = _viewController;
    _flag = 101;
    [self creatverifyNoticeView];
    [_controller.navigationController.view addSubview:_adView];
    
    return;
    //    //完成
    //
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:_title message:_message delegate:self cancelButtonTitle:NSLocalizedString(@"取消", nil) otherButtonTitles:NSLocalizedString(@"wantVerify", nil), nil];
    alert.tag = 101;
    [alert show];
    [alert release];
    //    MyAppDataManager.personCon = _controller;
    //    BanBu_VideoAuthenViewController *verify = [[BanBu_VideoAuthenViewController alloc] initWithRegisterVerify:NO];
    //    [_controller.navigationController pushViewController:verify animated:YES];
    //    [verify release];
}

#pragma mark - 初始化视频认证说明界面
- (void)creatverifyNoticeView
{
    if (!_adView)
    {
        //2014年11月19日10:35:48 by 尹林 添加视频认证说明界面
        _adView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, __MainScreen_Width, __MainScreen_Height + 20)];
        _adView.backgroundColor = UIColorWithRGB(76, 77, 77, 0.5);
        UITextView * textView = [[UITextView alloc]initWithFrame:CGRectMake(20, 20, 280, __MainScreen_Height - 20)];
        //    _adWeb.delegate = self;
        textView.layer.cornerRadius = 7.0;
        textView.layer.masksToBounds = YES;
        textView.font = [UIFont systemFontOfSize:13.0];
        [textView setEditable:NO];
        textView.text = NSLocalizedString(@"verifyNoticeNew", nil);
        [textView sizeToFit];
        [textView setFrame: CGRectMake(20, (__MainScreen_Height - 20 - textView.frame.size.height)/2.0, 280, textView.frame.size.height + 50)];
        
        [_adView addSubview:textView];
        [textView release];
        
        UILabel * titleLa = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 280, 30)];
        titleLa.text = NSLocalizedString(@"videoVerify", nil);
        titleLa.textAlignment = kTextAlignmentCenter;
        titleLa.font = [UIFont boldSystemFontOfSize:16.0];
        [textView addSubview:titleLa];
        [titleLa release];
        textView.backgroundColor = [UIColor whiteColor];
        UIButton * canclebutton = [UIButton buttonWithType:UIButtonTypeCustom];
        [canclebutton setFrame:CGRectMake(237, 6,34, 34)];
        canclebutton.alpha = 0.7;
        [canclebutton setBackgroundImage:[UIImage imageNamed:@"cancelWeb.png"] forState:UIControlStateNormal];
        [canclebutton addTarget:self action:@selector(closeADView) forControlEvents:UIControlEventTouchUpInside];
        [textView addSubview:canclebutton];
        
        UIButton * verifyBu = [UIButton buttonWithType:UIButtonTypeCustom];
        [verifyBu setFrame:CGRectMake(0, textView.frame.size.height - 45, 280, 45)];
        [verifyBu addTarget:self action:@selector(gotoVerify) forControlEvents:UIControlEventTouchUpInside];
        [verifyBu setTitle:NSLocalizedString(@"wantVerify", nil) forState:UIControlStateNormal];
        verifyBu.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        NSString * buPath = [[NSBundle mainBundle] pathForResource:@"pre_txlBu" ofType:@"png"];
        [verifyBu setBackgroundImage:[UIImage imageWithContentsOfFile:buPath] forState:UIControlStateNormal];
        [textView addSubview:verifyBu];
    }
}
#pragma mark - 关闭视频认证说明界面
- (void)closeADView
{
    [_adView removeFromSuperview];
}
#pragma mark - 去视频认证
- (void)gotoVerify
{
    [self closeADView];
    if (_flag == 101)
    {
        MyAppDataManager.personCon = _controller;
        BanBu_VideoAuthenViewController *verify = [[BanBu_VideoAuthenViewController alloc] initWithRegisterVerify:NO];
        [_controller.navigationController pushViewController:verify animated:YES];
        [verify release];
        verify = nil;
        return;
    }
    if (_flag == 100)
    {
        BanBu_ApplyVipViewController *video = [[BanBu_ApplyVipViewController alloc] init];
        [_controller.navigationController pushViewController:video animated:YES];
        [video release];
        video = nil;
        return;
    }
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 1)
    {
        if(alertView.tag == 100)
        {
            BanBu_ApplyVipViewController *video = [[BanBu_ApplyVipViewController alloc] init];
            [_controller.navigationController pushViewController:video animated:YES];
            [video release];
        }
        else if(alertView.tag == 101)
        {
            MyAppDataManager.personCon = _controller;
            BanBu_VideoAuthenViewController *verify = [[BanBu_VideoAuthenViewController alloc] initWithRegisterVerify:NO];
            [_controller.navigationController pushViewController:verify animated:YES];
            [verify release];
        }
    }
    return;
}


@end
